$(function () {
    //等待加载
    loading();

    var devId = getQueryString("devId");
    ajaxplayAgain(1, devId, null);
    $(".vedioAD").click(function () {
        $(".sliderbox").empty();
        $("#void").empty();
        //$("#pic").empty();
        //等待加载
        loading();
        $("#void").show();
        $("#pic").hide();
        $(".picAD").removeClass("current");
        $(this).addClass("current");
        ajaxplayAgain(1, devId, null);
    });
    $(".picAD").click(function () {
        $(".sliderbox").empty();
        //$("#void").empty();
        $("#pic").empty();
        //等待加载
        loading();
        $("#void").hide();
        $("#pic").show();
        $(".vedioAD").removeClass("current");
        $(this).addClass("current");
        var ad_type = "p";
        ajaxplayAgainpic(1, devId, ad_type);
    });
    oversize("productName",18);
})


/**
 * 再次播放
 *
 * @param page 当前页数
 * @param devId
 *            内容商Id
 * @param flag
 *            标记需要video 还是picture "v"=video "p"=picture
 * @returns
 */
function ajaxplayAgain(page, devId, flag) {
    var url = "/Lvscore_User_M/myAds/ajaxplayAgain";
    $.post(url, {
        page: page,
        devId: devId,
        flag: flag
    }, function (data) {
        // sumpage：页容量（页面的数据条数）
        // nowpage：页码
        // developerAdsList：List<DeveloperAdsDto>
        // ad_id: 广告Id
        // ad_name: 广告名称
        // ad_type: 广告类型
        // duration: 广告时常
        // picture_num: 广告张数
        // pc_size: 广告大小
        // adv_url: 广告路径
        // delivery_price: 投放单价
        // plan_end: 投放时间
        // play_num: 广告播放数量
    	$(".sliderbox").empty();
        $("#void").empty();
      if(data.developerAdsList.length==0){
          $("#void").html('<p class="noResult"><img src="/Lvscore_User_M/userWeb/static/images/dissearch.png" alt="">暂时没有视频广告</p>')
       }
        $.each(data.developerAdsList, function (index, element) {
        	if(!isNotEmpty(element.ad_homepage)){
				element.ad_homepage="/Lvscore_User_M/userWeb/static/images/bm.png";
	    	}
            if (data.developerAdsList.ad_type = "video") {
            	
            	 var videoFinish="";
                 if (element.finish == 1) {
                 	videoFinish += "<input type='button' ad_type='video' ad_id='" + element.ad_id + "' value='已播放' class='plays'/>";
                 } else {
                 	videoFinish += "<input type='button' ad_type='video' ad_id='" + element.ad_id + "' value='播放' class='plays'/>";
                 	 var sliderbox="";
                 	 sliderbox+='<a href="javascript:void(0)"> <img src="'+element.ad_homepage+'" class="bgImg"/>'
                     +'<span class="center"><span class="productName">'+ element.ad_name +'</span><b><img src="/Lvscore_User_M/userWeb/static/images/recommend_icon.png" alt="" title="">'+parseFloat(element.delivery_price).toFixed(2)+'</b></span>'
                     +'<div class="imgMask"></div>'
                     +'<div class="hover_show">'
                         +'<h4>'+ element.ad_name +'</h4>'
                         +'<p>有效期至：' + element.plan_end +'</p>'
                         +'<p><span class="infm">'
                         +'<img src="/Lvscore_User_M/userWeb/static/images/recommend_icon.png">'
                         +parseFloat(element.delivery_price).toFixed(2)
                         +'</span>'
                         +'<span class="infm">'
                         +'<img src="/Lvscore_User_M/userWeb/static/images/recommend_icon2.png">'
                         + element.pc_size + '</span><span class="infm">'
                         +'<img src="/Lvscore_User_M/userWeb/static/images/recommend_icon3.png">'
                         + element.play_num +'次</span></p>'
                         +'<p>'+videoFinish+'</p>'
                     +'</div></a>'
                 }
                var video = "<li>" +
                    "<span class='hintbg'></span>" +
                    "<span class='center'><span class='productName'>" + element.ad_name + "</span><b><img src='/Lvscore_User_M/userWeb/static/images/recommend_icon.png' alt='' title=''>" + parseFloat(element.delivery_price).toFixed(2) + "</b></span>" +
                    "<img src='"+element.ad_homepage+"' class='bjHover'>" +
                    "<div class='backdrop'>" +
                    "<div class='bj'></div>" +
                    "<h2>" + element.ad_name + "</h2>" +
                    "<p>有效期至：" + element.plan_end + "</p>" +
                    "<i>" + element.duration + "</i>" +
                    "<ol>" +
                    "<li><span><img src='/Lvscore_User_M/userWeb/static/images/recommend_icon.png'></span>" + parseFloat(element.delivery_price).toFixed(2) + "</li>" +
                    "<li><span><img src='/Lvscore_User_M/userWeb/static/images/recommend_icon2.png'></span>" + element.pc_size + "</li>" +
                    "<li><span><img src='/Lvscore_User_M/userWeb/static/images/recommend_icon3.png'></span>" + element.play_num + "次</li>" +
                    "</ol>"+videoFinish+
                     "</div>" +
                    "</li>";
                	
                            
                
                
                
                $("#void").append(video);
                $(".sliderbox").append(sliderbox);
                $(".recommendBox ul li").hover(function () {
                    $(this).find(".backdrop").show();
                }, function () {
                    $(this).find(".backdrop").hide()
                });
            }
        });
        slider();
        playAd();
        //分页
        if($(".tcdPageCode").html()==""){
        	createPageVideo(data.sumpage,data.nowpage);
        }
//等待加载的效果消失
        $(".loadingBox").hide();
    }, "json");
}

/**
 * 再次播放图片广告
 * @param page当前页数
 * @param devId内容商ID
 * @param flag  v视频广告 p图片广告
 * @returns
 */
function ajaxplayAgainpic(page, devId, flag) {
    var url = "/Lvscore_User_M/myAds/ajaxplayAgain";
    $.post(url, {
        page: page,
        devId: devId,
        flag: flag
    }, function (data) {
        // sumpage：页容量（页面的数据条数）
        // nowpage：页码

        // developerAdsList：List<DeveloperAdsDto>
        // ad_id: 广告Id
        // ad_name: 广告名称
        // ad_type: 广告类型
        // duration: 广告时常
        // picture_num: 广告张数
        // pc_size: 广告大小
        // adv_url: 广告路径
        // delivery_price: 投放单价
        // plan_end: 投放时间
        // play_num: 广告播放数量
        $("#pic").empty();
    	$(".sliderbox").empty();
        if(data.developerAdsList.length==0){
            $("#pic").html('<p class="noResult"><img src="/Lvscore_User_M/userWeb/static/images/dissearch.png" alt="">暂时没有图片广告</p>');
             $(".loadingBox").hide();
        }
        $.each(data.developerAdsList, function (index, element) {
        	if(!isNotEmpty(element.ad_homepage)){
				element.ad_homepage="/Lvscore_User_M/userWeb/static/images/bm.png";
	    	}
        	if(!isNotEmpty(element.picture_num)){
        		element.picture_num=0;
        	}
        	if(!isNotEmpty(element.play_num)){
        		element.play_num=0;
        	}
        	var picFinish="";
        	if (element.finish == 1) {
        		picFinish += "<input type='button' ad_type='pic' ad_id='" + element.ad_id + "' value='已播放' class='plays'/>";
            } else {
            	picFinish += "<input type='button' ad_type='pic' ad_id='" + element.ad_id + "' value='播放' class='plays'/>";
            	 var sliderbox="";
                 sliderbox+='<a href="javascript:void(0)"> <img src="'+element.ad_homepage+'" class="bgImg"/>'
                         +'<span class="center"><span class="productName">'+ element.ad_name +'</span><b><img src="/Lvscore_User_M/userWeb/static/images/recommend_icon.png" alt="" title="">'+parseFloat(element.delivery_price).toFixed(2)+'</b></span>'
                         +'<div class="imgMask"></div>'
                         +'<div class="hover_show">'
                             +'<h4>'+ element.ad_name +'</h4>'
                             +'<i>' + element.picture_num + '张</i>'
                             +'<p>有效期至：' + element.plan_end +'</p>' 
                             +'<p><span class="infm">'
                             +'<img src="/Lvscore_User_M/userWeb/static/images/recommend_icon.png">'
                             +parseFloat(element.delivery_price).toFixed(2)
                             +'</span>'
                             +'<span class="infm">'
                             +'<img src="/Lvscore_User_M/userWeb/static/images/recommend_icon2.png">'
                             + element.pc_size + '</span><span class="infm">'
                             +'<img src="/Lvscore_User_M/userWeb/static/images/recommend_icon3.png">'
                             + element.play_num +'次</span></p>'
                             +'<p>'+picFinish+'</p>'
                         +'</div></a>'
            }
        	var s="<li>" +
            "<span class='hintbg'></span>" +
            "<span class='center'><span class='productName'>" + element.ad_name + "</span><b><img src='/Lvscore_User_M/userWeb/static/images/recommend_icon.png' alt='' title=''>" + parseFloat(element.delivery_price).toFixed(2) + "</b></span>" +
            "<img src='"+element.ad_homepage+"' class='bjHover' width='235px' height='135px'>" +
            "<div class='backdrop'>" +
            "<div class='bj'></div>" +
            "<h2>" + element.ad_name + "</h2>" +
            "<p>有效期至：" + element.plan_end + "</p>" +
            "<i>" + element.picture_num + "张</i>"+
            "<ol>" +
            "<li><span><img src='/Lvscore_User_M/userWeb/static/images/recommend_icon.png'></span>" + parseFloat(element.delivery_price).toFixed(2) + "</li>" +
            "<li><span><img src='/Lvscore_User_M/userWeb/static/images/recommend_icon2.png'></span>" + element.pc_size + "</li>" +
            "<li><span><img src='/Lvscore_User_M/userWeb/static/images/recommend_icon3.png'></span>" + element.play_num + "次</li>" +
            "</ol>"+
            picFinish
           
            
            s += "</div>" +
                "</li>";
            $("#pic").append(s);
            $(".sliderbox").append(sliderbox);
            $(".recommendBox ul li").hover(function () {
                $(this).find(".backdrop").show();
            }, function () {
                $(this).find(".backdrop").hide()
            });
        });
        slider();
        playAd();
        //分页
        if($(".tcdPageCode").html()==""){
        	createPagePic(data.sumpage,data.nowpage);
        }

//等待加载的效果消失
        $(".loadingBox").hide();

    }, "json");
}
//轮播
function slider(){
	if(isNotEmpty($('.sliderbox').text())){
		var slidermodel = new sliderModel($('.sliderbox'),$('.sliderbox a'),$('.lbtn'),$('.rbtn'));
	    var slider = new Sliders(slidermodel,false,2000,500,"red","green");
	    slider.go();
	    $(".sliderbox a").hover( function(){
	        $(this).find(".imgMask").show();
	        $(this).find(".hover_show").show();
	    },function(){
	        $(this).find(".imgMask").hide();
	        $(this).find(".hover_show").hide()
	    });
	}
}
//图片分页
function createPagePic(pages,pageNum){
	if(pages>1){
		$(".tcdPageCode").createPage({
	        pageCount:pages,
	        current:pageNum,
	        backFn:function(p){
	        	ajaxmyCollectionpic(p,"picture");
	        }
	    	});
	}
}
//视频分页
function createPageVideo(pages,pageNum){
	if(pages>1){
	$(".tcdPageCode").createPage({
        pageCount:pages,
        current:pageNum,
        backFn:function(p){
        	ajaxmyCollection(p,"video");
        }
    	});
	}
}	
	